package root.agent.demo.advisors;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.advisor.api.*;
import reactor.core.publisher.Flux;

import java.util.HashMap;
import java.util.Objects;

@Slf4j
public class ReadingTwoAdvisior implements CallAroundAdvisor, StreamAroundAdvisor {
    @Override
    public AdvisedResponse aroundCall(AdvisedRequest advisedRequest, CallAroundAdvisorChain chain) {
        return chain.nextAroundCall(before(advisedRequest));
    }

    private AdvisedRequest before(AdvisedRequest advisedRequest){
        HashMap<String,Object> map = new HashMap<>();
        map.put("userText",advisedRequest.userText());
        return AdvisedRequest.from(advisedRequest).userText("""
                {userText} Read the question again:{userText}
                """).userParams(map).build();
    }

    @Override
    public Flux<AdvisedResponse> aroundStream(AdvisedRequest advisedRequest, StreamAroundAdvisorChain chain) {
        return chain.nextAroundStream(before(advisedRequest));
    }

    @Override
    public String getName() {
        return ReadingTwoAdvisior.class.getSimpleName();
    }

    @Override
    public int getOrder() {
        return 200;
    }
}
